import {Injectable} from '@angular/core';
import {HttpUtilService} from "../../../../../services/http/http-util.service";
import {BarnTeam} from "../entity/barn-team";
import {Observable} from "rxjs";
import {ResponseEntity} from "../../../../../services/http/response-entity";
import {environment} from "../../../../../../environments/environment";
import {TeamUser} from "../entity/team-user";

@Injectable({
  providedIn: 'root'
})
export class BarnTeamService {

  private prefix = environment.serverName.system + "/team/"

  constructor(private http: HttpUtilService) {

  }

  /**
   * 保存
   * @param data
   * @param handleError
   */
  save(data: BarnTeam, handleError = true): Observable<BarnTeam> {
    return this.http.post<BarnTeam>(this.prefix + "save", data, handleError)
  }

  /**
   * 查询
   * @param param
   * @param current
   * @param pageSize
   * @param handleError
   */
  query(param: BarnTeam, current = 0, pageSize = 0, handleError = true): Observable<ResponseEntity<BarnTeam[]>> {
    return this.http.getPage<BarnTeam[]>(this.prefix + "query", current, pageSize, handleError, param)
  }

  /**
   * 主键查询
   * @param pid
   * @param handleError
   */
  getById(pid: string, handleError = true): Observable<BarnTeam> {
    return this.http.get<BarnTeam>(this.prefix + "getById?pid=" + pid, handleError)
  }

  /**
   * 查询某个team的用户情况
   * @param param
   * @param handleError
   * @param current
   * @param pageSize
   */
  getUsers(param: TeamUser, current = 0, pageSize = 0, handleError = true): Observable<ResponseEntity<TeamUser[]>> {
    return this.http.getPage(this.prefix + "getUsers", current, pageSize, handleError, param)
  }
}
